<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="md5.min.js"></script>
    <title>MD5 工具</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        font-size: 18px;
    }

    .md5-container {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
    }

    .md5-container label {
        display: block;
        margin-bottom: 10px;
    }

    .md5-container input {
        outline: none;
        width: 400px;
        height: 40px;
        border: unset;
        border-radius: 10px;
        border: 1px solid #ccc;
    }

    .md5-container input:hover {
        box-shadow: 0 0 10px #ccc;
    }

</style>
<body>
<div class="md5-container">
    <div>
        <label for="str">要加密的内容：</label><input type="text" name="str" id="str"/>
    </div>
    <div>
        <label for="md5_str1">一次加密的内容：</label><input type="text" name="md5_str1" id="md5_str1" value=""/>
    </div>
    <div>
        <label for="md5_str2"> 二次加密的内容($0)：</label><input type="text" name="md5_str2" id="md5_str2" value=""/>
    </div>
    <div>
        <label for="salt">加盐($1)：</label><input type="text" name="salt" id="salt" value=""/>
    </div>
    <div><label for="salt_format">加盐格式：</label><input type="text" name="salt_format" id="salt_format" placeholder="$0{$1}" value="$0{$1}"/></div>
    <div>
        <label for="res">结果：</label><input type="text" name="res" id="res"/>
    </div>
</div>
<script>
    let items = document.getElementsByTagName("input")
    for (let i = 0; i < items.length; i++) {
        items[i].addEventListener("input", function () {
            document.getElementById("md5_str1").value = md5(document.getElementById("str").value)
            document.getElementById("md5_str2").value = md5(document.getElementById("md5_str1").value)
            let saltFormat = document.getElementById("salt_format").value
            document.getElementById("res").value = md5(saltFormat.replace("$0", document.getElementById("md5_str2").value).replace("$1", document.getElementById("salt").value))
        })
    }
</script>
</body>
</html>